package com.mopeso;

import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;
/**
 * Activity的基类
 */

public abstract class BaseActivity extends FragmentActivity {

    protected BaseActivity mActivity;
    protected RelativeLayout rlTitleBar;//标题栏跟布局
    protected ImageView ivBack;//返回键
    protected TextView tvTitle;//标题
    protected TextView right_text;//标题副按钮
    protected Button btSuctionBottom;//吸底的通栏按钮(悬浮在屏幕最底部) 默认gone 有需要的可以在实现类对其操作
    protected boolean ifSystemOk = true;
    protected ImageView mImageRight;
    private View vi_tap_bar;
    protected RelativeLayout rlTitle20;

    //布局文件ID
    protected void beforeOnCreate() {

    }

    //布局文件ID
    protected abstract int getContentViewId();

    //初始化View
    public abstract void onBindView();

    //获得savedInstanceState
    public void onBindViewsavedInstanceState(Bundle savedInstanceState) {

    }

    //初始化数据
    public abstract void initData();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        beforeOnCreate();
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//竖屏
        super.onCreate(savedInstanceState);
        // 避免从桌面启动程序后，会重新实例化入口类的activity
        if (!this.isTaskRoot()) {
            Intent intent = getIntent();
            if (intent != null) {
                String action = intent.getAction();
                if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN.equals(action)) {
                    finish();
                    return;
                }
            }
        }

        mActivity = this;
        //透明状态栏
//        setActionBarStatus();
        setContentView(R.layout.activity_base);
        FrameLayout frameLayout = findViewById(R.id.fl_sub_class);
        LayoutInflater.from(this).inflate(getContentViewId(), frameLayout, true);

        onBindView();
        initData();
        onBindViewsavedInstanceState(savedInstanceState);

    }

    /**
     * 设置沉浸式(透明)状态栏
     **/
    public void setActionBarStatus() {
        //透明状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0 全透明实现
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);//calculateStatusColor(Color.WHITE, (int) alphaValue)
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4 全透明实现

            //透明状态栏
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            //透明导航栏
            //  getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        }
    }

    /**
     * Activity跳转动画
     **/
    public void startActivity(Class<?> cls, Bundle bundle) {

        Intent intent = new Intent(getApplicationContext(), cls);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }


    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onStop() {
        super.onStop();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
